package edu.pinkhub.shiro_test.controller;

import java.util.List;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.pinkhub.shiro_test.entity.Depts;
import edu.pinkhub.shiro_test.service.DeptsService;
import edu.pinkhub.shiro_test.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author zhangsan
 * @email qis@gmail.com
 * @date 2022-06-28 18:46:57
 */
@RestController
@RequestMapping("/depts")
public class DeptsController {
    @Autowired
    private DeptsService deptsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R DeptsList(Integer page, Integer limit){
        Integer start=(page-1)*limit;
        Integer offset=3;
        QueryWrapper<Depts> wrapper=new QueryWrapper<>();
        wrapper.last(" limit "+start+" , "+offset);
        List<Depts> list = deptsService.list(wrapper);
        long count = deptsService.count();
        R r=new R();
        r.put("msg"," ");
        r.put("code","0");
        r.put("data",list);
        r.put("count",count);
        return r;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("user:depts:update")
    public R update(@RequestParam("params") String params){
        Depts depts = JSONUtil.toBean(params, Depts.class);
        deptsService.updateById(depts);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("user:depts:delete")
    public R delete(Integer id){
        deptsService.removeById(id);
        return R.ok();
    }
//
//    /**
//     * 信息
//     */
//    @RequestMapping(value = "/info/{deptid}", method = HttpMethod.GET)
//    //@RequiresPermissions("user:depts:info")
//    public R info(@PathVariable("deptid") Integer deptid){
//		Depts depts = deptsService.getById(deptid);
//
//        return R.ok().put("depts", depts);
//    }
//
//    /**
//     * 保存
//     */
//    @RequestMapping(value = "/save", method = HttpMethod.POST)
//    //@RequiresPermissions("user:depts:save")
//    public R save(@RequestBody Depts depts){
//		deptsService.save(depts);
//
//        return R.ok();
//    }
//
//

}
